#pragma once

#include "RenderPass.hpp"
#include "EffectPass.hpp"
#include "D3D11Shader.hpp"




namespace Engine
{
	namespace Video
	{
		class D3D11EffectPass
			: public EffectPass
		{
		private:

			ID3D11DevicePtr                      m_device;
			boost::optional<StaticReflection>    m_vertexReflection;
			ID3D11InputLayoutPtr                 m_inputLayout;
			boost::optional<D3D11VertexShader>   m_vertexShader;
			boost::optional<D3D11PixelShader>    m_pixelShader;

		public:

			D3D11EffectPass(const ID3D11DevicePtr& device);



			/**
			 * Add a vertex shader to this pass.
			 */
			void addVertexShader(const QByteArray& asciiData, const std::string& entryPoint, const StaticReflection& vertexReflection);

			/**
			 * Add a pixel shader to this pass.
			 * Can only be done when the pass has a vertex shader.
			 */
			void addPixelShader(const QByteArray& asciiData, const std::string& entryPoint);




			/**
			 * Optimize memory usage by freeing all reflection data and the compiled effect's buffers.
			 */
			void optimize();




			/**
			 * Draws this pass, using the given context, mesh and parameters.
			 */
			void draw(const ID3D11DevicePtr& device, D3D11DeviceContext& context, const RenderPass& params);

		private:

			/**
			 * Creates an InputLayout for this vertex shader's InputSignature.
			 */
			void createInputLayout();
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
